﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace passitumi
{
	class WindowsPreferenceManager : PreferenceManager
	{
		private string tempDownloadFilePath = passitumi.Properties.Settings.Default.downloadFilePath;
		private string tempDisplayName = passitumi.Properties.Settings.Default.displayName;

		/**
		 * Save the current user preferences.
		 */
		public void savePreferences()
		{
			Console.WriteLine("Preferences: Saving temporary application settings...");
			passitumi.Properties.Settings.Default.downloadFilePath = tempDownloadFilePath;
			passitumi.Properties.Settings.Default.displayName = tempDisplayName;
			passitumi.Properties.Settings.Default.Save();
			Console.WriteLine("Preferences: Application setings saved successfully.");
		}

		/**
		 * Retrieve the current download file path.
		 */
		public string getDownloadFilePath()
		{
			return passitumi.Properties.Settings.Default.downloadFilePath;
		}

		/**
		 * Retrieve the current user's display name.
		 */
		public string getDisplayName()
		{
			return passitumi.Properties.Settings.Default.displayName;
		}

		/**
		 * Update the location where files will download to (volatile update until saved).
		 */
		public void updateDownloadFilePath(string downloadFilePath)
		{
			Console.WriteLine("Preferences: Temporarily updating the download file path to - {0}", downloadFilePath);
			tempDownloadFilePath = downloadFilePath;
		}

		/**
		 * Update the name that users are displayed as to their peers (volatile update until saved).
		 */
		public void updateDisplayName(string displayName)
		{
			Console.WriteLine("Preferences: Temporarily updating the display name - {0}", displayName);
			tempDisplayName = displayName;
		}

		/**
		 * Set the display name to a default value.
		 */
		public void setDefaultDisplayName()
		{
			tempDisplayName = System.Environment.UserName;
			this.savePreferences();
		}

		/**
		 * Check to see if this is the first time this application is being run.
		 */
		public bool isFirstRun()
		{
			if (passitumi.Properties.Settings.Default.firstRun)
			{
				// First run detected, update settings, define default display name and save the preferences
				passitumi.Properties.Settings.Default.firstRun = false;
				this.setDefaultDisplayName();
				this.savePreferences();
				return true;
			}
			// First run not detected
			return false;
		}
	}
}
